package com.fengkai.filepost.pdfoutstream.test.my;

import java.util.Scanner;
import java.util.Stack;

/**
 * @author Fengkai
 * @creat 2023/5/5
 */
public class JiangJin {
    //第一行 员工数量  第二行 每位员工分配到的数字
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        int count  = Integer.parseInt(scanner.nextLine());
        int [] nums = new int[count];
        for (int i = 0; i < count; i++) {
            nums[i] = scanner.nextInt();
        }
        String result = getResult(nums);
        System.out.println(result);
    }

    private static String getResult (int[] nums) {
        int length = nums.length;
        //用栈去做
        Stack<Integer> maxNums = new Stack<>();
        int [] resluts = new int[length];
        int i = 0;
        while (i <length){
            if (maxNums.isEmpty() || nums[maxNums.peek()] >= nums[i]){
                maxNums.push(i++);
            }else {
                resluts[maxNums.peek()] = (nums[i] - nums[maxNums.peek()]) * (i - maxNums.peek());
                maxNums.pop();
            }
        }
        while (!maxNums.isEmpty()){
            resluts[maxNums.peek()] = nums[maxNums.pop()];
        }
        StringBuilder stringBuilder = new StringBuilder();
        for (int j = 0; j <resluts.length ; j++) {
                stringBuilder.append(resluts[j]).append(" ");
        }
        return stringBuilder.substring(0, stringBuilder.length() - 1);
    }
}
